package com.qzsoft.zhjd.server.modules.cement.handler;

import java.math.BigDecimal;

import com.qzsoft.zhjd.server.common.utils.NumberUtils;
import com.qzsoft.zhjd.server.modules.cement.entity.CollectCementDataWeightEntity;
import com.qzsoft.zhjd.server.modules.cement.entity.CollectCementMatchEntity;
import com.qzsoft.zhjd.server.modules.cement.model.CementCollectDataModel;

/**
 * @ClassName CementDataHandler
 * @Description 生产重量处理
 * @author linhuawei
 * @since 2022-02-28
 */
public class CementDataWeightHandler {

    /**
     * @Title coverTo
     * @Description 处理重量信息
     * @param originalData
     * @param match
     * @return
     */
    public static CollectCementDataWeightEntity coverTo(CementCollectDataModel originalData, CollectCementMatchEntity match) {
        // 处理重量数据
        CollectCementDataWeightEntity dataWeight = new CollectCementDataWeightEntity();

        // 获取实际用量
        dataWeight.setGravel1Act(originalData.getGravel1Act());
        dataWeight.setGravel2Act(originalData.getGravel2Act());
        dataWeight.setGravel3Act(originalData.getGravel3Act());
        dataWeight.setGravel4Act(originalData.getGravel4Act());
        dataWeight.setGravel5Act(originalData.getGravel5Act());
        dataWeight.setGravel6Act(originalData.getGravel6Act());
        dataWeight.setPowder1Act(originalData.getPowder1Act());
        dataWeight.setPowder2Act(originalData.getPowder2Act());
        dataWeight.setWaterAct(originalData.getWaterAct());
        dataWeight.setBatchWeight(originalData.getBatchWeight());

        // 根据是否有配方信息，判读如何处理理论重量
        if (null != match) {
            // 集料重量
            BigDecimal totalWeight = dataWeight.getBatchWeight();
            dataWeight.setGravel1Theo(NumberUtils.countValue(totalWeight, match.getGravel1(), 2));
            dataWeight.setGravel2Theo(NumberUtils.countValue(totalWeight, match.getGravel2(), 2));
            dataWeight.setGravel3Theo(NumberUtils.countValue(totalWeight, match.getGravel3(), 2));
            dataWeight.setGravel4Theo(NumberUtils.countValue(totalWeight, match.getGravel4(), 2));
            dataWeight.setGravel5Theo(NumberUtils.countValue(totalWeight, match.getGravel5(), 2));
            dataWeight.setGravel6Theo(NumberUtils.countValue(totalWeight, match.getGravel6(), 2));
            dataWeight.setPowder1Theo(NumberUtils.countValue(totalWeight, match.getPowder1(), 2));
            dataWeight.setPowder2Theo(NumberUtils.countValue(totalWeight, match.getPowder2(), 2));
            dataWeight.setWaterTheo(NumberUtils.countValue(totalWeight, match.getWater(), 2));
        } else {
            // 如果没有查询到生产配比，使用采集到的理论重量
            // 理论重量
            dataWeight.setGravel1Theo(originalData.getGravel1Theo());
            dataWeight.setGravel2Theo(originalData.getGravel2Theo());
            dataWeight.setGravel3Theo(originalData.getGravel3Theo());
            dataWeight.setGravel4Theo(originalData.getGravel4Theo());
            dataWeight.setGravel5Theo(originalData.getGravel5Theo());
            dataWeight.setGravel6Theo(originalData.getGravel6Theo());
            dataWeight.setPowder1Theo(originalData.getPowder1Theo());
            dataWeight.setPowder2Theo(originalData.getPowder2Theo());
            dataWeight.setWaterTheo(originalData.getWaterTheo());
        }

        // 集料实际重量
        BigDecimal gravelAct = NumberUtils.sum(dataWeight.getGravel1Act(), dataWeight.getGravel2Act(),
                dataWeight.getGravel3Act(), dataWeight.getGravel4Act(), dataWeight.getGravel5Act(),
                dataWeight.getGravel6Act());
        dataWeight.setGravelAct(gravelAct);

        // 水泥实际重量
        BigDecimal powderAct = NumberUtils.sum(dataWeight.getPowder1Act(), dataWeight.getPowder2Act());
        dataWeight.setPowderAct(powderAct);

        // 水实际重量
        BigDecimal waterAct = null == dataWeight.getWaterAct() ? BigDecimal.ZERO : dataWeight.getWaterAct();
        dataWeight.setWaterAct(waterAct);

        // 集料理论重量
        BigDecimal gravelTheo = NumberUtils.sum(dataWeight.getGravel1Theo(), dataWeight.getGravel2Theo(),
                dataWeight.getGravel3Theo(), dataWeight.getGravel4Theo(), dataWeight.getGravel5Theo(),
                dataWeight.getGravel6Theo());
        dataWeight.setGravelTheo(gravelTheo);

        // 水泥理论重量
        BigDecimal powderTheo = NumberUtils.sum(dataWeight.getPowder1Theo(), dataWeight.getPowder2Theo());
        dataWeight.setPowderTheo(powderTheo);

        // 水理论重量
        BigDecimal waterTheo = null == dataWeight.getWaterTheo() ? BigDecimal.ZERO : dataWeight.getWaterTheo();
        dataWeight.setWaterTheo(waterTheo);

        // 返回重量数据
        return dataWeight;
    }

}
